<?php
$con=mysqli_connect("localhost","root","youhanmo1997");
if(!$con){
	die("error:".mysqli_errno()) ;
}  
mysqli_select_db($con,"students_management");

$sql= "SELECT * FROM students S,courses C,course_select CS Where S.sid=CS.sid AND CS.cid=C.cid ";

if(($_POST['cname']!="")&&($_POST['cid']=="")){
 $sql .="AND C.cname='".$_POST['cname']."';";
}else if(($_POST['cname']=="")&&($_POST['cid']!="")){
$sql .="AND C.cid='".$_POST['cid']."';";
}else if(($_POST['cname']!="")&&($_POST['cid']!="")){
	 $sql .="AND C.cid='".$_POST['cid']."' AND C.cname='".$_POST['cname'].";";
}

$result = mysqli_query($con,$sql);
if (!$result) {
 printf("Error: %s\n", mysqli_error($con));
 exit();
}
$arr = array();
while($row=mysqli_fetch_array($result)){
	$arr[] = $row;
}
echo json_encode($arr);

?>